package com.baosight.risk.web.xtzy;

import com.baosight.risk.api.xtzy.IXtzyCompanyService;
import com.baosight.risk.api.xtzy.IXtzyUserPermissionService;
import com.baosight.risk.api.xtzy.IXtzyUserService;
import com.baosight.risk.base.controller.BaseController;
import com.baosight.risk.common.annotation.Log;
import com.baosight.risk.common.bean.BeanUtils;
import com.baosight.risk.common.enums.BusinessType;
import com.baosight.risk.common.enums.IntegralType;
import com.baosight.risk.common.result.AjaxResult;
import com.baosight.risk.common.utils.StringUtils;
import com.baosight.risk.service.quartz.entity.SyncEmpleeEntitiy;
import com.baosight.risk.service.rire.entity.RireRiskWarningStatus;
import com.baosight.risk.service.xtzy.entity.XtzyUser;
import com.baosight.risk.service.xtzy.entity.XtzyUserPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.Map;

/**
 * 类 名: XtzyUserPermissionController
 * 描 述: 权限申请
 * 作 者: 黄鑫
 * 创 建：2022年09月06日
 * 版 本：v2.2.0
 * 历 史: (版本) 作者 时间 注释
 */
@Slf4j
@RestController
@RequestMapping("/xtzy/userPermission")

@Api(value = "权限申请", description = "权限申请", produces = MediaType.APPLICATION_JSON)
public class XtzyUserPermissionController extends BaseController {

    @Autowired
    private IXtzyUserPermissionService userPermissionService;

    /**
     * 权限申请查询列表selctIndex
     *
     * @param userPermission
     * @return
     */
    @GetMapping("/selectUserPermissionList")
    @Log(title = "权限申请查询列表", integralType = IntegralType.Type2)
    @ApiOperation("权限申请查询列表")
    public AjaxResult selectUserPermissionList(XtzyUserPermission userPermission) {
        if (null == userPermission) {
            userPermission = new XtzyUserPermission();
        }
        return getResultPage(userPermissionService.selectUserPermissionList(userPermission));
    }


    /**
     * 提交权限申请
     *
     * @param userPermission
     * @return
     */
    @PostMapping("submitAuth")
    @ApiOperation("提交权限申请")
    public AjaxResult submitAuth(@RequestBody XtzyUserPermission userPermission) {
        log.info("提交权限申请参数：" + userPermission.toString());
        try {
            userPermissionService.submitUserPermission(userPermission);
        }catch (Exception e) {
            return error(e.getMessage());
        }
        return toAjax(1);
    }

    /**
     * 保存用户
     *
     * @param user
     * @return
     */
    @PostMapping("save")
    @ApiOperation("保存权限申请")
    public AjaxResult save(@RequestBody XtzyUserPermission user) {
        log.info("保存权限申请：" + user.toString());
        Integer result = userPermissionService.savePermissionUser(user);
        return toAjax(result);
    }

    /**
     * 进入查看页面
     *
     * @return
     */
    @GetMapping("selectByPermissionUser")
    @ApiOperation("根据ID查询")
    public AjaxResult selectByPermissionUser(@RequestParam("id") String id) {
        return success(userPermissionService.selectByPermissionUser(id));
    }
}
